package com.netdevsdk.demo.liveview.live;

import java.io.File;

import javax.swing.JDialog;
import javax.swing.JOptionPane;

import com.netdevsdk.demo.NetDemo;
import com.netdevsdk.demo.util.Common;
import com.netdevsdk.lib.NetDEVSDKLib;
import com.netdevsdk.lib.NetDEVSDKLib.NETDEV_MANUAL_SNAPSHOT_PARAM_S;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * 
 * @introduction Live view snapshot
 * @description Support IPC/NVR/VMS
 */
public class ManualSnapshot extends JDialog{
	private static final long serialVersionUID = 1L;
	private JTextField textLaneID;
	private JTextField textTrigID;
	NetDEVSDKLib netdevsdk = NetDEVSDKLib.NETDEVSDK_INSTANCE;
	
	public ManualSnapshot() {
		this.setSize(300,300);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		this.setTitle("Manual Snap");
		this.setVisible(true);
		
        Toolkit toolkit=Toolkit.getDefaultToolkit();
        Dimension screenSize =toolkit.getScreenSize();
        int x=(screenSize.width-this.getWidth())/2;
        int y=(screenSize.height-this.getHeight())/2;
        this.setLocation(x,y);
		getContentPane().setLayout(null);
		
		textLaneID = new JTextField();
		textLaneID.setBounds(121, 41, 81, 21);
		getContentPane().add(textLaneID);
		textLaneID.setColumns(10);
		
		textTrigID = new JTextField();
		textTrigID.setBounds(121, 87, 81, 21);
		getContentPane().add(textTrigID);
		textTrigID.setColumns(10);
		
		JLabel lblLaneID = new JLabel("Lane ID:");
		lblLaneID.setBounds(57, 44, 54, 15);
		getContentPane().add(lblLaneID);
		
		JLabel lblTriggerID = new JLabel("Trig ID:");
		lblTriggerID.setBounds(57, 90, 54, 15);
		getContentPane().add(lblTriggerID);
		
		JButton btnOK = new JButton("确认");
		btnOK.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			       if(null == NetDemo.lpUserID) {
			            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
			            return;
			            }
			       NETDEV_MANUAL_SNAPSHOT_PARAM_S stManual = new NETDEV_MANUAL_SNAPSHOT_PARAM_S();
			       stManual.dwLaneCode = Integer.parseInt(textLaneID.getText());
			       stManual.dwTriggerID = Integer.parseInt(textTrigID.getText());

			       if(null != NetDemo.lpUserID){
			            if(NetDemo.ChannelID == 0){
			                JOptionPane.showMessageDialog(null, "Please select the channel first.");
			                return;
			            }
			            boolean bRet = NetDemo.netdevsdk.NETDEV_MaunalSnapshot(NetDemo.lpUserID, NetDemo.ChannelID, stManual);
			            if(bRet){
			                JOptionPane.showMessageDialog(null, "manual snapshot success!");
			            }else {
			                JOptionPane.showMessageDialog(null, "Make sure the device supports manual snapshot.");
			            }
			        }
			}
		});
		btnOK.setBounds(95, 161, 93, 23);
		getContentPane().add(btnOK);
	}
}
